const express = require('express');
const router = express.Router();
const multer = require('multer');
const path = require('path');

// 表单验证
const expressJoi = require('@escook/express-joi')
const { admin_login,admin_update_PWD } = require('../rule/adminRule')

const adminService = require('../service/adminService')

// 登录
router.post('/login', expressJoi(admin_login), adminService.login);

// 验证码
router.get('/security', adminService.security);

// 修改头像
router.post('/upLoadAvatar', multer({
    dest: path.join(__dirname, '../file/avatar') //设置文件的存储路径
}).single('file'), adminService.updateAvatar);

// 获取头像
router.get('/avatar/:name', adminService.getFile);

// 获取用户信息
router.get('/info', adminService.info);

// 修改密码
router.post('/updatePWD', expressJoi(admin_update_PWD), adminService.updatePWD);


module.exports = router;
